<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title></title>
	<link href="../../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="../../css/reset.css" />
	<link rel="stylesheet" type="text/css" href="../../css/footer.css" />
	<link rel="stylesheet" type="text/css" href="../../css/swiper-3.4.2.min.css" />
	<link rel="stylesheet" type="text/css" href="../../css/classfly.css" />
	<link rel="stylesheet" type="text/css" href="../../css/colalition.css" />
	<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=cEywgU0hSEVd31BAlBWPYT331WtoNNdB"></script>
	<style type="text/css">
		/*修改底部字体颜色*/
		
		.foot:nth-child(2) {
			color: #e83023;
		}
		
		#content {
			padding-top: 1.180555rem;
			overflow: auto;
		}
		
		a.jindian {
			color: #E83023;
			border: 0.013888rem solid #E83023;
			border-radius: 0.416666rem;
			display: inline-block;
			width: 1.111111rem;
			height: 0.555555rem;
			font-size: 0.277777rem;
			text-align: center;
			padding: 0.069444rem 0.041666rem 0.069444rem 0.041666rem;
			line-height: 0.416666rem;
			position: relative;
			top: -0.069444rem;
		}
		
		.jindian:hover {
			color: #E83023;
			text-decoration: none;
		}
		
		#cityA {
			z-index: 50;
			padding: 0.069444rem;
			border-radius: 0.277777rem;
			position: absolute;
			top: 0.3rem;
			left: 0.277777rem;
			height: 0.6rem;
			color: #e83023;
		}
		
		#cityA span:nth-child(2) {
			position: relative;
		}
		
		#banner_top {
			width: 100%;
			height: 1.3667rem;
			margin-top: 0.45rem;
			position: absolute;
			z-index: 25;
			overflow: hidden;
		}
		
		#banner_top .search {
			float: left;
			width: 84%;
			margin-left: 0.2rem;
			padding-top: 0;
		}
		
		.search-input {
			border: 1px solid gainsboro;
		}
		
		#banner_top>a {
			float: right;
			width: 0.7333rem;
			height: 0.7333rem;
			margin-right: 0.42rem;
			margin-top: 0.05rem;
		}
		
		#banner_top>a img {
			width: 100%;
			height: 100%;
		}
		
		.jindianN {
			display: block;
			margin-bottom: 15px;
		}
		
		.jindianN .address {
			margin-left: 0;
		}
		
		.adress {
			margin-left: 0;
		}
		
		.tell {
			color: #e8323e;
		}
		
		.item {
			width: 1.1944rem;
			margin-bottom: 0;
			margin: 0 auto;
			display: block;
			/* margin-left: 0.2rem; */
			margin-right: 0.4rem;
		}
		
		.item-title {
			display: inline-block;
			margin-left: 0;
			margin-top: 0;
			border: 0;
		}
		
		.item-title.active {}
		
		.item-wrapper {
			width: 2.2222rem;
			text-align: center;
			padding-top: 0.12rem;
		}
		
		.item-wrapper a {
			text-align: center;
		}
	</style>
	<script src="../../js/flexible.min.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
	<div id="wrap">
		<div id="main">
			<div id="header">
				<i class="c-icon c-icon-chevron-bottom"></i>
				<a href="citySel.html" id="cityA" style="">
					<span id="city" style="font-size: 15px;width: 80px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;display: block;float: left;"></span>
					<sapn style="display: inline-table;float: left;margin: 3px;font-size: 15px;"></sapn>
				</a>
				<p id="headTitle" style="background-color: #f7f7f7;">联盟</p>
				<a id="headUser" href="../personage/person_info.html"><img class="headUser" src="../../images/msg.png" /></a>
			</div>
			<div id="content">
				<!--内容-->
				<div class="banner-container">
					<!--搜索框-->
					<div id="banner_top">
						<div class="search">
							<input type="text" class="search-input" id="searchShopName">
						</div>
						<a class="myinfo" href="../personage/person_myinfo.html">
							<img src="../../images/msg.png" />
						</a>
					</div>
				</div>

				<!--内容-->
				<div class="banner-container">
					<!--搜索框-->
					<div>

						<div class="swiper-container">
							<div class="swiper-wrapper">
							</div>
						</div>

					</div>

					<p class="slogen">遇见仁和，遇见未来</p>
					<div class="menu">
						<span class="item-wrapper"><a onclick="cuxiao()"><img class="item" src="../../images/coalltion/04.png"/><div class="item-title">促销活动</div></a></span>
						<span class="item-wrapper"><a id="fujin" onclick="fujin()"><img class="item" src="../../images/coalltion/02.png"/><div class="item-title">附近</div></a></span>
						<span class="item-wrapper"><a href="./classfly/classfly.html"><img class="item" src="../../images/coalltion/03.png"/><div class="item-title">分类</div></a></span>
					</div>
				</div>
				<div class="category">

				</div>
			</div>
		</div>
		<div id="foot" class="row">
			<a class="foot col-xs-3 col-sm-3" href="../kaoqin/index2.html">
				<img class="footImg" src="../../images/15.png" />
				<p>管理</p>
			</a>
			<a class="foot col-xs-3 col-sm-3" href="colalition.html">
				<img class="footImg" src="../../images/14.png" />
				<p>联盟</p>
			</a>
			<a class="foot col-xs-3 col-sm-3" href="../store/store.html">
				<img class="footImg" src="../../images/11.png" />
				<p>商城</p>
			</a>
			<a class="foot col-xs-3 col-sm-3" href="../personage/personIndex.html">
				<img class="footImg" src="../../images/13.png" />
				<p>我的</p>
			</a>
		</div>
	</div>
	<form id="wxForm" name="wxForm" method="post"></form>
</body>
<script src="../../js/jquery-2.2.3.min.js"></script>
<script src="../../js/jquery.cookie.js" type="text/javascript"></script>
<script src="../../js/swiper.min.js"></script>
<script src="../../js/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<!--<script src="../../js/rhAdmin.js" type="text/javascript" charset="utf-8"></script>-->
<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></script>
<script>
	$().ready(function() {
			var tokenzb = $.cookie("tokenRh");
			if (!tokenzb) {
				window.location.href = "../login/login/login.html";
			}
			currentyf(tokenzb);
			var memberId;
			var img = "../../images/coalltion/01.png";
			//获取get值
			function getQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
				var r = window.location.search.substr(1).match(reg);
				if (r != null) return decodeURI(r[2]);
				return null;
			}
			//定位
			// var city = remote_ip_info['city'];
			// console.log(city);
			// $("#city").html(city);
			// var n = $("#city").width();
			//判断是否存在url?后参数参数
			function getQueryString1(name) {
				var reg = eval("/" + name + "/g");
				var r = window.location.search.substr(1);
				var flag = reg.test(r);
				if (flag) {
					return true;
				} else {
					return false;
				}
			}
			//轮播图
			$.ajax({
				url: "http://47.104.13.109/mall-service/areapic/search",
				type: "GET",
				data: {
					areaId: "changchun"
				},
				success: function(data) {
					console.log(data)
					var tpl =
						'<div class="swiper-slide"><a href="##"><img src="' + data.pic1 + '" /></a></div>' +
						'<div class="swiper-slide"><a href="##"><img src="' + data.pic2 + '"/></a></div>' +
						'<div class="swiper-slide"><a href="##"><img src="' + data.pic3 + '"/></a></div>' +
						'<div class="swiper-slide"><a href="##"><img src="' + data.pic4 + '"/></a></div>';
					$('.swiper-wrapper').append(tpl);
					// 轮播图渲染后 初始化轮播图
					//					var mySwiper = new Swiper('.swiper-container', {
					//						direction: 'horizontal',
					//						loop: true,
					//						autoplay: 5000,
					//					});
					$(".swiper-slide img").error(function() {
						$(this).attr('src', img);
					})
				},
				error: function(e) {
					console.log('获取轮播图数据出错:', e);
				}
			});
			//模糊搜索
			function isContains(str, substr) {
				return new RegExp(substr).test(str);
			}
			// 获取数据，渲染页面
			//获取一级列表
			$(".search-input").on('keyup', function(e) { //当按下按键时  
				if (e.which == 13) {
					var shopName = document.getElementById("searchShopName").value;
					if (shopName != null) {
						window.location.href = "nearby/searchshop.html?" + shopName;
					}
				}
			});
		})
		//搜索
	function search() {
		$.ajax({
			type: "get",
			url: "http://47.104.13.109/mall-service/lolcart/oneList",
			async: true,
			success: function(data) {
				//获取二级列表
				//					console.log(data)
				$.each(data, function(idx, item) {
					var tpl_title =
						'<div class="category-title" style="padding:0.1rem">' +
						'<p class="title">' + item.name + '</p>' +
						'<span class="more" style="padding:0.1rem"><a href="classfly/classfly.html?classfly=' + escape(item.name) + '">更多<img width="10" height="10" src="../../images/coalltion/more.png" /></a></span>' +
						'</div>';
					$.ajax({
						type: "get",
						url: "http://47.104.13.109/mall-service/lolcart/twoList",
						async: true,
						data: {
							cartId: item.catId
						},
						success: function(res) {
							var catIdOne = "";
							//								console.log(res);
							for (var i = 0; i < res.length; i++) {
								if (res[i].catId) {
									catIdOne += res[i].catId + ','
								}
							}
							if (catIdOne != "") {
								//									console.log(catIdOne)
								$.ajax({
									type: "get",
									url: "http://47.104.13.109/mall-service/shop/listCat2",
									async: true,
									data: {
										pageNum: 1,
										pageSize: 666,
										catId: catIdOne,
										shopName: $(".search-input").val()
									},
									success: function(res1) {
										console.log(res1.list);
										$.each(res1.list, function(idx, item) {
											//												if(idx == 0) {
											if (isContains(item.shopSpare2, city) || isContains(item.shopAdd, city)) {
												var tel = item.tel || 19022222222;
												var tpl_modals =
													'<div class="modals">' +
													'<a class="jindianN"  href="commodity_details/commodity_details.html?shopId=' + item.shopId + '">' +
													'<div class="modals-title">' +
													'<span class="brand">' + item.shopName + '</span>' +
													'</div>' +
													'<div><img class="advertise" src="' + item.shopPic + '" /></div></a>' +
													'<div class="address"><img class="icon" src="../../images/coalltion/name.png" /><span>' + item.shopName +
													'</span></div>' +
													'<div class="address"><img class="icon" src="../../images/coalltion/shareN.png" /><span>' + item.shopSign +
													'</span></div>' +
													'<div class="address"><img class="icon" src="../../images/coalltion/newadress.png" /><span>' + item.shopAdd +
													'</span></div>' +
													//														'<div class="address"><img class="icon" src="../../images/coalltion/tel.png" /><a class="tell" href="tel:' + tel + '">联系电话' + tel +'</a>'
													'</div>' +
													'</div>';
												//													if(idx == 0) {
												//														$('.category').append(tpl_title);
												//													}
												$('.category').append(tpl_modals);
												//												}
											}
										});
									}
								});
							}
						},
						error: function(error1) {
							console.log(error1);
						}
					});
				});
			},
			error: function(error) {
				console.log(error)
			}
		});
	}
</script>
<script type="text/javascript">
	var latitude;
	var longitude;
	var speed;
	var accuracy;
	var cityName;
	var dingwei = "43.8219013261,125.3301296792";
	// 百度地图API功能
	function G(id) {
		return document.getElementById(id);
	}

	function currentyf(tokenzb) {
		$.ajax({
			cache: false,
			type: "GET",
			url: "http://47.104.13.109/member-service/member/mine/member?token=" + tokenzb,
			dataType: "JSON",
			async: false,
			error: function(error) {
				$.removeCookie('tokenzb', {
					expires: 7,
					path: '/'
				});
			},
			success: function(data) {
				console.log(data);
				memberId = data.id;
				getOpenId(memberId);
			}
		});
	}

	function getOpenId(memberId) {
		var url = window.location.href;
		if (url.indexOf("?") > 0) {
			if (url.indexOf("city") > 0) {
				cityName = decodeURI(url.split("=")[1]);
				$("#city").html(cityName);
				$.ajax({
					cache: false,
					type: "GET",
					url: "http://47.104.13.109/pay-service/savearea?memberId=" + memberId + "&areaName=" + cityName,
					async: false,
					success: function(data4) {
						if (data4 == "success") {
							loadShop(city);
						} else {
							ggf(memberId);
						}
					}
				});
				loadShop(decodeURI(url.split("=")[1]));
				//如果是重新选择城市那么就加入到缓存中
			} else {
				var url1 = url.split("?")[1];
				alert("url1" + url1);
				var url2 = url1.split("&");
				alert(url2[0].split("=")[1]);
				$.ajax({
					cache: false,
					type: "GET",
					url: "http://47.104.13.109/pay-service/setOpenId?code=" + url2[0].split("=")[1] + "&memberId=" + memberId,
					async: false,
					error: function(error) {},
					success: function(data) {
						ggf(memberId);
					}
				});
			}
		} else {
			getArea(memberId);
		}
	}

	function getArea(memberId) {
		$.ajax({
			cache: false,
			type: "GET",
			url: "http://47.104.13.109/pay-service/getarea?memberId=" + memberId,
			async: false,
			success: function(data4) {
				if (data4 != "") {
					cityName = data4;
					$("#city").html(cityName);
					loadShop(data4);
				} else {
					$.ajax({
						cache: false,
						type: "GET",
						url: "http://47.104.13.109/pay-service/checkoutTicket?memberId=" + memberId,
						async: false,
						success: function(data5) {
							if (data5 == "fail") {
								$.get("http://47.104.13.109/pay-service/getOpenId3?memberId=" + memberId, {
									rediretUrl: location.href
								}, function(data) {
									//alert(data.url);
									if (data != "") {
										$("#wxForm").prop("action", data.url);
										$("#wxForm").submit();
									}
								}, "json");
							} else {
								ggf(memberId);
							}
						}
					});
				}
			}
		});
	}

	function ggf(memberId) {
		var urlf = window.location.href.split('#')[0];
		var newUrl = "http://47.104.13.109/pay-service/getJSSDK?memberId=" + memberId + "&url=" + urlf;
		//alert(newUrl);
		$.ajax({
			cache: false,
			type: "GET",
			url: newUrl,
			dataType: "JSON",
			async: false,
			success: function(data2) {
				console.log(data2.appId);
				console.log(data2.timestamp);
				console.log(data2.noncestr);
				console.log(data2.signature);
				wx.config({
					debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
					appId: data2.appId, // 必填，公众号的唯一标识
					timestamp: data2.timestamp, // 必填，生成签名的时间戳
					nonceStr: data2.noncestr, // 必填，生成签名的随机串
					signature: data2.signature, // 必填，签名，见附录1
					jsApiList: ['checkJsApi', 'openLocation', 'getLocation'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
				});
				wx.ready(function() {
					// config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
					wx.checkJsApi({
						jsApiList: ['getLocation'], // 需要检测的JS接口列表，所有JS接口列表见附录2,  
						success: function(res) {
							if (res.checkResult.getLocation == false) {
								alert('你的微信版本太低，不支持微信JS接口，请升级到最新的微信版本！');
								cityName = "切换城市";
								$("#city").html(cityName);
							}
						}
					});
					wx.getLocation({
						success: function(res) {
							latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90    
							longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。    
							speed = res.speed; // 速度，以米/每秒计    
							accuracy = res.accuracy; // 位置精度    
							//alert("获取到位置信息：latitude="+latitude+"accuracy="+accuracy);
							getBaiduPosition(longitude, latitude);
							//alert(accuracy);  
						},
						cancel: function(res) {
							cityName = "切换城市";
							$("#city").html(cityName);
						}
					});
				});
				wx.error(function(res) {
					// config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。  
					//alert("切换城市");   
					cityName = "切换城市";
					$("#city").html(cityName);
				});
			}
		});
	}
	//百度地图api功能
	function G(id) {
		return document.getElementById(id);
	}
	//坐标转换
	function getBaiduPosition(lng, lat) {
		var url = "http://api.map.baidu.com/geoconv/v1/?coords=" + lng + "," + lat + "&from=1&to=5&ak=cEywgU0hSEVd31BAlBWPYT331WtoNNdB";
		$.ajax({
			url: url,
			type: 'GET',
			contentType: "application/json",
			dataType: 'jsonp', //这里要用jsonp的方式不然会报错
			success: function(data) {
				if (data.status == 0) {
					dingwei = data.result[0].x + "," + data.result[0].y;
					//$("#city").html(cityName);
					var map = new BMap.Map("allmap");
					var point = new BMap.Point(data.result[0].x, data.result[0].y);
					var gc = new BMap.Geolocation();
					var gc2 = new BMap.Geocoder();
					gc.getCurrentPosition(function(r) {
						if (this.getStatus() == BMAP_STATUS_SUCCESS) {
							//appLat = r.point.lat;  
							//appLng = r.point.lng;  
							var pt = r.point;
							gc2.getLocation(pt, function(rs) {
								var addComp = rs.addressComponents;
								var province = addComp.province;
								var city = addComp.city;
								var area = addComp.district;
								$("#city").html(city);
								$.ajax({
									cache: false,
									type: "GET",
									url: "http://47.104.13.109/pay-service/savearea?memberId=" + memberId + "&areaName=" + city,
									async: false,
									success: function(data4) {
										if (data4 == "success") {
											loadShop(city);
										} else {
											ggf(memberId);
										}
									}
								});
							});
						}
					}, {
						enableHighAccuracy: true
					});
				}
			}
		});
	}

	function fujin() {
		window.location.href = "nearby/nearby.html";
	}

	function cuxiao() {
		window.location.href = "./activity/activity.html?city=" + encodeURI($("#city").text());
	}

	function loadShop(shopSpare2) {
		$.ajax({
			type: "get",
			url: "http://47.104.13.109/mall-service/lolcart/oneList",
			async: true,
			success: function(data) {
				//获取二级列表
				//					console.log(data)
				$.each(data, function(idx, item) {
					var tpl_title =
						'<div class="category-title" style="padding:0.1rem">' +
						'<p class="title">' + item.name + '</p>' +
						'<span class="more" style="padding:0.1rem"><a href="classfly/classfly.html?classfly=' + escape(item.name) + '">更多<img width="10" height="10" src="../../images/coalltion/more.png" /></a></span>' +
						'</div>';
					$.ajax({
						type: "get",
						url: "http://47.104.13.109/mall-service/lolcart/twoList",
						async: true,
						data: {
							cartId: item.catId
						},
						success: function(res) {
							var catIdOne = "";
							//								console.log(res);
							for (var i = 0; i < res.length; i++) {
								if (res[i].catId) {
									catIdOne += res[i].catId + ','
								}
							}
							if (catIdOne != "") {
								console.log(catIdOne);
								console.log(shopSpare2);
								$.ajax({
									type: "get",
									url: "http://47.104.13.109/mall-service/shop/listCat2",
									async: true,
									data: {
										pageNum: 1,
										pageSize: 666,
										catId: catIdOne,
										shopSpare2: shopSpare2
									},
									success: function(res1) {
										console.log(res1.list);
										$.each(res1.list, function(idx, item) {
											//												if(idx <= 6) {
											console.log(11);
											// if (isContains(item.shopSpare2, city)||isContains(item.shopAdd, city)) {
											var tel = item.tel || 19022222222;
											var tpl_modals =
												'<div class="modals">' +
												'<a class="jindianN"  href="commodity_details/commodity_details.html?shopId=' + item.shopId + '">' +
												/*'<div class="modals-title">' +
												'<span class="brand">' + item.shopName + '</span>' +
												'</div>' +*/
												'<div><img class="advertise" src="' + item.shopPic + '" /></div></a>' +
												'<div class="address"><img class="icon" src="../../images/coalltion/name.png" /><span>' + item.shopName +
												'</span></div>' +
												'<div class="address"><img class="icon" src="../../images/coalltion/shareN.png" /><span>' + item.shopSign +
												'</span></div>' +
												'<div class="address"><img class="icon" src="../../images/coalltion/newadress.png" /><span>' + item.shopAdd +
												'</span></div>' +
												//														'<div class="address"><img class="icon" src="../../images/coalltion/tel.png" /><a class="tell" href="tel:' + tel + '">联系电话' + tel +'</a>'+
												'</div>' +
												'</div>';
											if (idx == 0) {
												$('.category').append(tpl_title);
											}
											$('.category').append(tpl_modals);
											//												}
										});
									}
								});
							}
						},
						error: function(error1) {
							console.log(error1);
						}
					});
				});
			},
			error: function(error) {
				console.log(error)
			}
		});
	}
</script>

</html>